package com.bdqn.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.bdqn.component.ServerRespsone;
import com.bdqn.entity.Banner;
import com.bdqn.entity.Barmenu;
import com.bdqn.entity.Food;
import com.bdqn.service.FoodService;
import com.bdqn.util.Page;

@CrossOrigin
@RestController
public class RestFullController {

	@Autowired
	private  FoodService  foodService;
	
	@RequestMapping("/indexJson")
	public  Map<String, Object>  indexJson(){
		 Map<String, Object>  map=new  HashMap<String, Object>();
		 //查询主页的banner
		 List<Banner>  bannes=foodService.getBannerByPostion(1);
		 //主页导航菜单
		 List<Barmenu>   barMenus=foodService.getBarmenus();
		 
		 map.put("bannes", bannes);
		 map.put("barMenus", barMenus);
		 return  map;
	}
	
	
	@RequestMapping("/foodJson")
	public  Map<String, Object>  foodJson(@RequestParam(defaultValue="1")Integer pageIndex,@RequestParam(defaultValue="4")Integer  pageSize,String  foodName ){
		 Map<String, Object>  map=new  HashMap<String, Object>();
		 ServerRespsone<Page<Food>>  rs=foodService.getPageFood(pageIndex, pageSize, foodName);
		 if(rs.isSuccess()){
			 map.put("status", "success");
			 map.put("keyword", foodName);
			 map.put("page", rs.getData());
			 return  map;
		 }
		 map.put("status", "error");
		 map.put("msg", "查询数据数据失败");
		 return  map;
	}
	
	
}
